<template>
    <div class="table">
        <h1 style="text-align: center">报道详情</h1>
        <div class="handle-box">
            <el-input v-model="select_word" placeholder="输入关键字" class="handle-input mr10"></el-input>
            <el-button type="primary" icon="search"  plain @click="search">搜索</el-button>
            <el-button type="primary" icon="el-icon-download" plain  @click="downloadfile">导出报道信息</el-button>
        </div>
        <div>
            <el-table :data="tableData" border style="width: 100%"  max-height="600">
                <el-table-column type="index" width="55"></el-table-column>
                <el-table-column property="phone" label="会议名称" width="120"></el-table-column>
                <el-table-column property="subject" label="姓名" width="120"></el-table-column>
                <el-table-column property="place" label="身份证号码" width="120"></el-table-column>
                <el-table-column property="name" label="工作单位" width="120"></el-table-column>
                <el-table-column property="idcard" label="报道时间"></el-table-column>
                <el-table-column property="company" label="备注"></el-table-column>
                <el-table-column label="操作" fixed="right" width="150">
                    <template slot-scope="scope">
                        <el-button
                            size="mini" type="primary"
                            @click="handleEdit(scope.$index, scope.row)">修改</el-button>
                        <el-button
                            size="mini"
                            type="danger"
                            @click="delOne(scope.$index, scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination v-show="page"
                           @size-change="handleSizeChange"
                           @current-change="handleCurrentChange"
                           :current-page.sync="pageNum"
                           :page-size="10"
                           layout="prev, pager, next, jumper"
                           :total="count">
            </el-pagination>
            <el-pagination v-show="!page"
                           @size-change="handleSizeChange"
                           @current-change="handleCurrentChange1"
                           :current-page.sync="pageNum1"
                           :page-size="10"
                           layout="prev, pager, next, jumper"
                           :total="count1">
            </el-pagination>
            <el-dialog title="修改信息" :visible.sync="updateDogVis"  size="small">
                <el-form :model="updateForm" ref="updateForm" label-width="100px" class="demo-ruleForm">
                    <el-form-item label="姓名">
                        <el-input v-model="updateForm.name"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="handleupdata('updateForm')">立即修改</el-button>
                        <el-button @click="resetForm('ruleForm')">重置</el-button>
                    </el-form-item>
                </el-form>
            </el-dialog>
            <el-dialog title="添加成绩信息" :visible.sync="addDogVis" size="small" >
                <el-form :model="addForm"  ref="addForm" label-width="100px" class="demo-ruleForm">
                    <el-form-item label="考试科目">
                        <el-input v-model="addForm.subject"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="handleadd('addForm')">立即添加</el-button>
                    </el-form-item>
                </el-form>
            </el-dialog>
        </div></div>

</template>

<script>
    export default {
        data() {
            return {
                tableData:[  {

                }],
                updateForm:{

                },
                addForm:{

                },
                select_word:'',
                pageNum:1,
                pageNum1:1,
                count:1,
                count1:1,
                updateDogVis:false,
                addDogVis:false,
                page:true
            }
        },
        created(){
            this.getData();
        },
        methods: {
            downloadfile(){
                window.location.href='/text/achievement/getexcel';
            },
            getData(){
                this.$axios.get('/text/achievement/query?pageNum=1').then((res)=>{
                    this.tableData=res.data.data.list;
                    this.count=res.data.data.total;
                })
            },
            handleEdit(index, row) {
                this.updateDogVis = true;
                this. ruleForm= row;
            },
            handleupdata(){
                this.$axios.put('/text/achievement/update?' +
                    'id='+this.ruleForm.id+
                    '&name=' + this.ruleForm.name +
                    "&phone=" + this.ruleForm.phone+
                    "&sex=" + this.ruleForm.sex+
                    "&seatnumber=" + this.ruleForm.seatnumber+
                    "&remarks=" + this.ruleForm.remarks+
                    "&grade=" + this.ruleForm.grade+
                    "&company=" + this.ruleForm.company+
                    "&idcard=" + this.ruleForm.idcard
                ).then((res) => {
                    if(res.data.code==200)
                    {
                        this.$message({
                            message: '修改信息成功！！',
                            type: 'success'
                        });
                    }
                    this.getData();
                    this.updateDogVis = false;
                })
            },
            delOne(index, row) {
                this.$axios.delete('/text/achievement/deletebyid?' +
                    'id=' + row.id
                ).then((res) => {
                    this.getData();
                    this.$message.info('删除成功');
                })
            },
            search(select_word){
                this.$axios.get('/text/achievement/queryfuzzy?pageNum=1&idcard='+this.select_word).then((res) => {
                    this.count1=res.data.data.data.total;
                    this.tableData= res.data.data.data.list;
                    this.page=false
                })
            },
            handleadd() {
                this.$axios.post('/text/achievement/create?' +
                    'subject=' + this.ruleForm1.subject +
                    '&place=' + this.ruleForm1.place +
                    '&name=' + this.ruleForm1.name +
                    "&phone=" + this.ruleForm1.phone+
                    "&sex=" + this.ruleForm1.sex+
                    "&seatnumber=" + this.ruleForm1.seatnumber+
                    "&remarks=" + this.ruleForm1.remarks+
                    "&grade=" + this.ruleForm1.grade+
                    "&company=" + this.ruleForm1.company+
                    "&idcard=" + this.ruleForm1.idcard
                ).then((res) => {
                    if(res.data.code==200)
                    {
                        this.$message({
                            message: '添加成功！！',
                            type: 'success'
                        });
                    }
                    else if(res.data.code==402)
                    {
                        this.$message.error('')
                    }
                    this.getData();
                    this.addDogVis = false;
                    this.resetForm('ruleForm1')
                })

            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            },
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(pageNum) {
                this.$axios.get('/text/achievement/query?pageNum='+pageNum).then((res)=>{
                    this.tableData=res.data.data.list
                })
            },
            handleCurrentChange1(pageNum1,select_word) {
                this.$axios.get('/text/achievement/queryfuzzy?pageNum='+pageNum1+'&idcard='+this.select_word).then((res)=>{
                    this.tableData= res.data.data.data.list;
                })
            },
        }
    }
</script>

<style scoped>
    .table{
        padding: 20px;
    }
    .handle-box{
        margin-bottom: 20px;
    }
    .handle-select{
        width: 20px;
    }
    .handle-input{
        width: 300px;
        display: inline-block;
    }
    .drbutton{
        width: 100px;
        height: 40px;
        border-radius: 5px;
        background-color: white;
    }
    .drinput{
        width: 300px;
        height: 35px;
        border-radius: 5px;
        border: 1px #d3e0e9 solid;
    }
</style>
